package com.example.esdemo.controller;

import com.example.esdemo.pojo.Position;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @Authther: mrwu
 * @date:2021/5/18-05
 * @Description:com.example.esdemo.controller
 */
@RestController
public class PositionController {
    @Autowired
    RestHighLevelClient restHighLevelClient;
    @GetMapping("/position")
    public SearchHit[] getAll(){
        try {
            SearchRequest lagou_position = new SearchRequest("lagou_position");
            //可以配置分页及查询参数
//            lagou_position.source(new SearchSourceBuilder().from(10));

            SearchResponse lagou_postion = restHighLevelClient.search(lagou_position, RequestOptions.DEFAULT);
            SearchHit[] hits = lagou_postion.getHits().getHits();
            return hits;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

}
